const util = {};
util.isNotCmdKey = (event) => {
  var eventTemp = event;
  var isNotCmdKey = false;
  if(event.data && event.data.domEvent && event.data.domEvent.$){
    eventTemp = event.data.domEvent.$;
  }
  if(eventTemp.ctrlKey || eventTemp.altKey || eventTemp.metaKey){ // metaKey -- mac键
    return false;
  }
  var keyCode = eventTemp.keyCode;

  //A~Z
  if(keyCode >= 65 && keyCode <= 90){
    return true;
  }
  //0~9
  if(keyCode >= 48 && keyCode <= 57){
    return true;
  }
  //numkeyboard
  if(keyCode >= 96 && keyCode <= 111){
    return true;
  }
  //enter space key
  if(keyCode ==13 || keyCode ==32){
    return true;
  }
  //backspace del key
  if(keyCode ==8 || keyCode ==46){
    return true;
  }

  //符号键
  if((keyCode >= 186 && keyCode <= 192) || (keyCode >= 219 && keyCode <= 222)){
    return true;
  }

  // 未知键，输入法常用
  if (keyCode === 229) {
    return true;
  }

  return false;

}

util.isDirectionKey = (e) => {
  return e.keyCode == 37 || e.keyCode == 38 || e.keyCode == 39 || e.keyCode == 40;
}

util.isDelete = (e) => {
  return e.keyCode == 46;
}
util.isBackspace = (e) => {
  return e.keyCode == 8;
}
util.isInput = (e) => {
  if (util.isBackspace(e) || util.isDelete(e) || util.isDirectionKey(e)) return false;
  return util.isNotCmdKey(e);
}

util.isUndoRedo = (e) => {
  // CKEDITOR.CTRL + 90 /*Z*/,
  // CKEDITOR.CTRL + 89 /*Y*/,
  // CKEDITOR.CTRL + CKEDITOR.SHIFT + 90 /*Z*/
  let isZ = e.keyCode === 90;
  let isY = e.keyCode === 89;
  return (isZ && e.ctrlKey) || (isY && e.ctrlKey)
}

util.isEnter = (e) => {
  return e.keyCode ==13 || e.keyCode ==32;
}

util.isCmdKey = (e) => {
  // fix: 91 mac的command键 按下的时候会记录问题
  return  e.keyCode === 16 || e.keyCode === 17 || e.keyCode === 18 || e.keyCode === 27 || e.keyCode === 91;
}

util.isCut = (e) => {
  return e.keyCode === 88 && e.ctrlKey;
}

export default util;